<?php
	include 'mysql.php';
	session_set_cookie_params(3600);
	session_start();
	
	$content = '';
	$title = 'Remont Admin';
	$h1 = '';
	$mesg = '';
	$chat = '';
	$admin_menu = '';
	$user_name = '';
	
	include 'fnc_all.php';
	
	
	if(!isset($_SESSION['login'])){
		if(isset($_GET['action'])){
			switch ($_GET['action']){
				case 'login_do': login_do(); break;//авторизація +
				default: login(); break;//форма авторизації + 
			}
		}else{
			login();
		}
		include 'tpl.php'; echo $login_tpl;//вивід шаблона
	}else{
		$user_name = $_SESSION['login'];
		
		chat();
	
		if($_SESSION['perm'] == 1){
			include 'fnc_admin.php';
			$admin_menu = <<<TPL
				<li class="dropdown">
					<a data-toggle="dropdown" class="dropdown-toggle" href="#">Адміністрування<b class="caret"></b></a>
					<ul class="dropdown-menu">
						<li><a href="/?action=list_user">Співробітники</a></li>
						<li><a href="/?action=list_news">Новини</a></li>
						<li><a href="/?action=list_complaint">Скарги і побажання</a></li>
					</ul>
				</li>
TPL;
		}		
		
		if($_SESSION['perm'] == 2){
			include 'fnc_manager.php';
		}
		
		if($_SESSION['perm'] == 3){
			include 'fnc_master.php';
		}
		
		if($_SESSION['perm'] == 4){
			include 'fnc_manager_st.php';
		}
		
		if($_SESSION['perm'] == 5){
			include 'fnc_stock.php';
		}
		
		if(isset($_GET['action'])){
			switch ($_GET['action']){
				//функції доступні всім працівникам 
				case 'logout': logout(); break;//вихід +
				case 'list_news_all': list_news_all(); break;//список новин +
				case 'long_story': long_story(); break;//повна новина +
				case 'list_complaint_all': list_complaint_all(); break;//список жалоб + 
				case 'add_complaint_do': add_complaint_do(); break;//додавання жалоби +
				case 'list_page_all': list_page_all(); break;//статичні сторінки +
				case 'filemanager': filemanager(); break;// +
				case 'user_profile': user_profile(); break; 
				case 'editor_profile': editor_profile(); break;
				case 'edit_profile_do': edit_profile_do(); break;
				case 'allusers': allusers(); break; 
				
				//функції адміна
				case 'add_user_do': add_user_do(); break;//+
				case 'add_user': add_user(); break;//+
				case 'delete_user_do': delete_user_do(); break;//+
				case 'list_user': list_user(); break; //+
				case 'editor_user': editor_user(); break;//+
				case 'edit_user_do': edit_user_do(); break;//+
				case 'add_news': add_news(); break;//+
				case 'add_news_do': add_news_do(); break;//+
				case 'list_news': list_news(); break;//+
				case 'delete_news_do': delete_news_do(); break;//+
				case 'editor_news': editor_news(); break;//+
				case 'edit_news_do': edit_news_do(); break;//+
				case 'list_complaint': list_complaint(); break;
				case 'delete_complaint_do': delete_complaint_do(); break;//+
				case 'list_page': list_page(); break;//+
				case 'add_page': add_page(); break;//+
				case 'add_page_do': add_page_do(); break;//+
				case 'delete_page_do': delete_page_do(); break;//+
				case 'edit_page_do': edit_page_do(); break;//+
				case 'editor_page': editor_page(); break;//+
				case 'list_orders': list_orders(); break;//+
				case 'delete_orders_do': delete_orders_do(); break;//+
				case 'edit_orders_do': edit_orders_do(); break;//+
				case 'editor_orders': editor_orders(); break;//+
				case 'rating': rating(); break; 
				case 'history': history(); break; 
				case 'best': best(); break; 
				case 'statik': statik(); break; 
				case 'edit_points_do': edit_points_do(); break;
				case 'back_remont': back_remont(); break;
				
				
				//функції менеджера
				case 'list_orders': list_orders(); break;
				case 'add_order': add_order(); break;
				case 'add_order_do': add_order_do(); break;
				case 'work_bool': work_bool(); break;
				case 'give_bool': give_bool(); break;
				case 'print_but': print_but(); break; 
				case 'print_but2': print_but2(); break; 
				case 'my_table': my_table(); break; 
				case 'history': history(); break; 
				case 'history_year': history_year(); break; 
				case 'edit_diagnosis_do': edit_diagnosis_do(); break; 
				case 'refusal_bool': refusal_bool(); break; 
				case 'dod_but': dod_but(); break; 
				case 'dod_but_do': dod_but_do(); break; 
				case 'price1_bool': price1_bool(); break;
				case 'price2_bool': price2_bool(); break;
				case 'backup': backup(); break;
				case 'edit_job_do': edit_job_do(); break;
				case 'edit_points_do': edit_points_do(); break;
				case 'fine_master': fine_master(); break;
				
				//функції мастера
				case 'list_orders': list_orders(); break;
				case 'take_bool': take_bool(); break;
				case 'my_table': my_table(); break; 
				case 'make_order_table': make_order_table(); break;
				case 'make_order': make_order(); break;
				case 'do_bool': do_bool(); break; 
				case 'dont_bool': dont_bool(); break;
				case 'history': history(); break; 
				case 'history_year': history_year(); break; 
				case 'edit_diagnosis_do': edit_diagnosis_do(); break; 
				case 'dod_but': dod_but(); break; 
				case 'dod_but_do': dod_but_do(); break; 
				case 'edit_what_aparat_do': edit_what_aparat_do(); break; 
				case 'edit_date_end': edit_date_end(); break; 
				case 'what_yes': what_yes(); break; 
				case 'what_no': what_no(); break; 
				case 'what_do': what_do(); break; 
				case 'what_dont': what_dont(); break; 
				case 'ball': ball(); break; 
				case 'ball_all': ball_all(); break; 
				
				//функції доступні кладовщику 
				case 'list_orders': list_orders(); break;
				case 'ord_bool': ord_bool(); break; 
				case 'come_bool': come_bool(); break; 
				case 'no_come_bool': no_come_bool(); break; 
				case 'history': history(); break; 
				case 'my_table': my_table(); break; 
				case 'make_order_table': make_order_table($relay); break;
				case 'execute_order': execute_order(); break;
				case 'del_order': del_order(); break;

				
				default: list_orders(); break;
			}
		}else{
			list_orders();
		}
		
		if(isset($mesg) && $mesg != ''){
			$tmp = $mesg;
			$mesg = '<div class="row-fluid"><div class="alert"><a data-dismiss="alert" class="close">×</a>'.$mesg.'</div></div>';
		}
		
		include 'tpl.php'; echo $main_tpl;//вивід шаблона
	}
?>